SELECT T.*,
(
CASE
WHEN (NOW() BETWEEN IFNULL(T.BEGIN_DATE, NOW()) AND IFNULL(T.END_DATE, NOW()))
THEN '1'
ELSE '2'
END) AS valid_code
FROM c1_user t
WHERE (CASE WHEN t.FLAG_CODE = 'registration-vip' THEN (t.code = :code OR t.mobile_phone = :code) ELSE t.code = :code END)
AND INSTR(t.FLAG_CODE, :flagCode) > 0
